var request = require('request'),
	cheerio = require('cheerio'),
	baseUrl = 'http://www.marketwatch.com/investing/stock/{0}/analystestimates',
	ticker = process.argv[2],
	url = baseUrl.replace('{0}', ticker);

request(url, function(err, resp, body) {
	var $ = cheerio.load(body),
		$tds = $('.snapshot tbody tr td'),
		opinion = {
			Current: $($tds.get(1)).text().replace(/^\s+|\s+$/gm,''),
			PriceTarget: parseFloat($($tds.get(3)).text().replace(/^\s+|\s+$/gm, '')),
			OpinionsCount: parseInt($($tds.get(5)).text().replace(/^\s+|\s+$/gm, ''))
		},
		opinions = [opinion],
		opinionsString = JSON.stringify(opinions);
	
	console.log(opinionsString);
});